package com.ye.personnel.common.utils;

import cn.hutool.core.date.*;
import cn.hutool.core.io.FileUtil;
import cn.hutool.http.HttpUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Month;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.*;

/**
 * @author ye
 * @Description
 * @create 2022-03-16 15:23
 */
@Slf4j
public class HelpUtils {

    /**
     * 获取24位字符的UUID
     * @return
     */
    public static String get24UUID(){
        UUID id= UUID.randomUUID();
        String[] idd = id.toString().split("-");
        return idd[0]+idd[1]+idd[4];
    }

    /**
     * 获取UUID
     * @return
     */
    public static String getUUID(){
        String uuid = UUID.randomUUID().toString();
        //去掉“-”符号
        return uuid.replaceAll("-", "");
    }

    /**
     * 指定日期的周系数
     * @param date
     * @return
     */
    public static Integer dayForWeek(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(Calendar.DAY_OF_WEEK);
    }

    /**
     * 指定日期的月份
     * @param date
     * @return
     */
    public static Integer getMonth(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(Calendar.MONTH)+1;
    }

    /**
     * 获取某天的开始结束时间
     * @param dayStr
     * @return
     */
    public static HashMap<String,String> getDayStartAndEndTime(String dayStr){
        HashMap<String, String> stringHashMap = new HashMap<>();
        if(StringUtils.isBlank(dayStr)){
            String date = DateUtil.today();
            stringHashMap.put("startDate",date + " 00:00");
            stringHashMap.put("endDate",date+ " 23:59");
        }else{
            int year = DateUtil.year(new Date());
            String newStr = dayStr.replace(".", "-");
            String date = year + "-"+ newStr;
            stringHashMap.put("startDate",date + " 00:00");
            stringHashMap.put("endDate",date+ " 23:59");
        }
        return stringHashMap;
    }


    /**
     * 目标时间是否在今天之前
     * @param targetDate
     * @return
     */
    public static boolean timeIsArrived(Date targetDate) {
        if(Objects.isNull(targetDate)){
            return false;
        }
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String nowDate = simpleDateFormat.format(new Date());
        String targetDateStr = simpleDateFormat.format(targetDate);
        if (nowDate.compareTo(targetDateStr) <= 0) {
            return false;//未到点
        }
        return true;//到点了
    }


    /**
     * 数字保留2位小数
     * @param num
     * @return
     */
    public static double setScaleNumber(Double num){
        BigDecimal bg = new BigDecimal(num);
        return bg.setScale(2, RoundingMode.HALF_UP).doubleValue();
    }

    /**
     * 获取比例
     * @param leftNum
     * @param rightNum
     * @return
     */
    public static BigDecimal getRate(int leftNum,int rightNum){
        if(rightNum  == 0){
            return BigDecimal.ZERO;
        }
        BigDecimal left = new BigDecimal(String.valueOf(leftNum));
        BigDecimal right = new BigDecimal(String.valueOf(rightNum));
        return left.divide(right, 2, RoundingMode.HALF_UP).stripTrailingZeros();
    }

    /**
     * 获取比例
     * @return
     */
    public static BigDecimal getRateBigDecimal(BigDecimal leftNum,BigDecimal rightNum){
        if(rightNum.compareTo(BigDecimal.ZERO) == 0 || leftNum.compareTo(BigDecimal.ZERO) == 0){
            return BigDecimal.ZERO;
        }
        return leftNum.divide(rightNum, 2, RoundingMode.HALF_UP).stripTrailingZeros();
    }

    /**
     * 字节转kb/mb/gb
     * @param size
     * @return
     */
    public static String getPrintSize(long size) {
        DecimalFormat df = new DecimalFormat("#.00");
        String fileSizeString = "";
        String wrongSize = "0B";
        if(size == 0){
            return wrongSize;
        }
        if (size < 1024){
            fileSizeString = df.format((double) size) + "B";
        }
        else if (size < 1048576){
            fileSizeString = df.format((double) size / 1024) + "KB";
        }
        else if (size < 1073741824){
            fileSizeString = df.format((double) size / 1048576) + "MB";
        }
        else{
            fileSizeString = df.format((double) size / 1073741824) + "GB";
        }
        return fileSizeString;
    }

    public static Integer getYearMonthDay(){
        DateTime dateTime = new DateTime();
        String yearMonth = DateUtil.format(dateTime, "yyyyMMddmm");
        return Integer.parseInt(yearMonth);
    }

    /**
     * 获取随机字符串
     * @param length
     * @return
     */
    public static String getRandomStr(int length) {
        String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(base.length());
            sb.append(base.charAt(number));
        }
        return sb.toString();
    }

    /**
     * 获取指定长度数据数字
     * @return
     */
    public static String getRandomNumber(int length) {
        String basePrefix = "123456789";
        String baseSuffix = "0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        int prefixPosition = random.nextInt(basePrefix.length());
        sb.append(basePrefix.charAt(prefixPosition));
        for (int i = 1; i < length; i++) {
            int number = random.nextInt(baseSuffix.length());
            sb.append(baseSuffix.charAt(number));
        }
        return sb.toString();
    }


    /**
     * 时间字符串
     * @return
     */
    public static String getTimeStr(Date createTime){
        return DateUtil.format(createTime, "yyyyMMddHHmmss");
    }

    /**
     * 日期字符串
     * @return
     */
    public static String getDateStr(Date createTime){
        return DateUtil.format(createTime, "yyyyMMdd");
    }

    /**
     * 获取分
     * @param price
     * @return
     */
    public static int getPriceInt(BigDecimal price){
        return price.multiply(new BigDecimal("100")).intValue();
    }

    /**
     * 数字转化
     * @param oldNumber
     * @param scale
     * @return
     */
    public static BigDecimal discountNumber(BigDecimal oldNumber, Integer scale){
        String price = oldNumber.divide(new BigDecimal(10), scale, RoundingMode.HALF_UP)
                .stripTrailingZeros().toPlainString();
        return new BigDecimal(price);
    }


    /**
     * 获取交易订单号
     * @param prefix
     */
    public static String getCustomerOrderNo(String prefix){
        String timeStr = DateUtil.format(new Date(), "yyyyMMddHHmmss");
        String number = timeStr + getRandomNumber(6);
        if(StringUtils.isNotBlank(prefix)){
            number = prefix+number;
        }
        return number;
    }

    /**
     * 时间对象转字符串
     * @param time
     * @return
     */
    public static String timeToStr(Date time){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
        return simpleDateFormat.format(time);
    }

    /**
     * 计算费率
     * @param price
     * @param dealRate
     * @return
     */
    public static BigDecimal getNewPrice(BigDecimal price,BigDecimal dealRate){
        BigDecimal rate = new BigDecimal("0.01");
        BigDecimal newRate = dealRate.multiply(rate);
        BigDecimal multiply = price.multiply(newRate);
        return multiply.setScale(2, RoundingMode.DOWN);
    }

    /**
     * 计算手续费
     * @param price
     * @param rate
     * @return
     */
    public static BigDecimal getServiceFee(BigDecimal price,BigDecimal rate){
        BigDecimal newRate = price.multiply(rate);
        return newRate.setScale(2, RoundingMode.UP);
    }

    public static BigDecimal getServiceFeeDown(BigDecimal price,BigDecimal rate){
        BigDecimal newRate = price.multiply(rate);
        return newRate.setScale(2, RoundingMode.DOWN);
    }

    public static void  deleteFileWithName(String dirName){
        File parentFile = new File(dirName);
        //目录存在，且为文件夹
        if (parentFile.exists() && parentFile.isDirectory()){
            //找出下面所有的文件或者文件夹名称
            File[] files = parentFile.listFiles(new FileFilter() {
                @Override
                public boolean accept(File pathname) {
                    return pathname.getName().startsWith("shareImg_");
                }
            });
            log.info("files==={}",files);
            assert files != null;
            for (File item : files){
                log.info("fileName==={}",item.getName());
                item.delete();
            }
        }
    }

    /**
     * 获取对象的属性值
     * @param o
     * @return
     */
    public static List<String> getFiledNames(Object o) {
        Field[] fields = o.getClass().getDeclaredFields();
        List<String> fieldNames = new ArrayList<>();
        for (int i = 0; i < fields.length; i++) {
            if(fields[i] != null){
                ApiModelProperty annotation = fields[i].getAnnotation(ApiModelProperty.class);
                if(annotation != null && !annotation.hidden()){
                    String keyValue = fields[i].getName() + "_" + annotation.value();
                    fieldNames.add(keyValue);
                }
            }
        }
        return fieldNames;
    }

    /**
     * 通过属性名获取属性值
     * @param filedName
     * @param o
     * @return
     */
    public static Object getFieldValueByName(String filedName, Object o) {
        try {
            String firstLetter = filedName.substring(0, 1).toUpperCase();
            String getter = "get" + firstLetter + filedName.substring(1);
            Method method = o.getClass().getMethod(getter, new Class[] {});
            Object value = method.invoke(o, new Object[] {});
            return value;
        } catch (Exception e) {
            log.error("获取属性值失败！" + e, e);
        }
        return null;
    }

    /**
     * 获取下个月的年月
     * @param startMonth
     * @param offset
     * @return
     */
    public static String nextMonth(String startMonth,int offset) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
        Date parse = DateUtil.parse(startMonth,"yyyy-MM");
        DateTime offsetDate = DateUtil.offset(parse, DateField.MONTH, -offset);
        return simpleDateFormat.format(offsetDate);
    }

    /**
     * 获取前一天的日期
     * @param startDate
     * @param offset
     * @return
     */
    public static String lastDay(String startDate,int offset) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date parse = DateUtil.parse(startDate,"yyyy-MM-dd");
        DateTime offsetDate = DateUtil.offsetDay(parse, -offset);
        return simpleDateFormat.format(offsetDate);
    }

    /**
     * 获取当前年月
     * @return
     */
    public static String getMonth(){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
        return simpleDateFormat.format(new Date());
    }

    /**
     * 获取指定日期的年月
     * @param date
     * @return
     */
    public static String getMonthStr(String date) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
        Date parse = simpleDateFormat.parse(date);
        return simpleDateFormat.format(parse);
    }

    /**
     * 获取指定日期的年月
     * @param date
     * @return
     */
    public static String getMonthStr(Date date) throws ParseException {
        if(date == null){
            return null;
        }
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
        return simpleDateFormat.format(date);
    }

    /**
     * 获取当月天数
     * @param yearMonth
     * @return
     */
    public static int getDaysOfMonth(String yearMonth) {
        String[] yearMonthArr = yearMonth.split("-");
        if(yearMonthArr.length <= 1){
            return 30;
        }
        Calendar calendar = Calendar.getInstance();
        calendar.clear();  //注意这里
        calendar.set(Calendar.YEAR, Integer.parseInt(yearMonthArr[0]));
        calendar.set(Calendar.MONTH, Integer.parseInt(yearMonthArr[1])-1);
        return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    }

    /**
     * 获取某月的开始结束时间
     * @param yearMonth
     * @return
     */
    public static Map<String,String> getStartAndEndDate(String yearMonth){
        int daysOfMonth = HelpUtils.getDaysOfMonth(yearMonth);
        String startDate = yearMonth + "-01 00:00:00";
        String endDate = yearMonth + "-" + daysOfMonth + " 23:59:59";
        Map<String, String> map = new HashMap<>();
        map.put("startDate",startDate);
        map.put("endDate",endDate);
        return map;
    }

    /**
     * 获取平均金额
     * @param decimal
     * @param average
     * @return
     */
    public static BigDecimal getAverageDecimal(BigDecimal decimal,Integer average){
        if(average <= 0){
            return BigDecimal.ZERO;
        }
        BigDecimal averageDecimal = new BigDecimal(average);
        return decimal.divide(averageDecimal,4, RoundingMode.HALF_UP).stripTrailingZeros();
    }

    public static BigDecimal getAverageDecimal2(BigDecimal decimal,Integer average){
        if(decimal == null){
            return BigDecimal.ZERO;
        }
        if(average == 0){
            return BigDecimal.ZERO;
        }
        BigDecimal averageDecimal = new BigDecimal(average);
        return decimal.divide(averageDecimal,2, RoundingMode.DOWN).stripTrailingZeros();
    }

    public static int getAverageInt(int leftNum,int rightNum){
        if(rightNum == 0){
            return 0;
        }
        double ceil = Math.ceil((double) leftNum / rightNum);
        return (int)ceil;
    }

    /**
     * 获取百分比
     * @param leftNum
     * @param rightNum
     * @return
     */
    public static String getPercent(BigDecimal leftNum,BigDecimal rightNum){
        if(rightNum.compareTo(BigDecimal.ZERO) == 0){
            return "0%";
        }
        BigDecimal divide = leftNum.divide(rightNum,4,RoundingMode.HALF_UP).stripTrailingZeros();
        BigDecimal multiply = divide.multiply(new BigDecimal("100")).stripTrailingZeros();
        return multiply.toPlainString() +"%";
    }

    public static long getPageTotal(long totalRow,int pageSize){
        if(totalRow <= 0){
            return 0;
        }
        return (totalRow + pageSize - 1) / pageSize;
    }

    /**
     * 获取延迟天数的日期
     * @param delayDays
     * @return
     */
    public static Date getDelayDate(int delayDays) {
        if(delayDays == 0){
            return null;
        }
        Date day = DateUtil.offsetDay(new Date(), delayDays);
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
        String format = sf.format(day) + " 23:59:59";
        return new DateTime(format, DatePattern.NORM_DATETIME_FORMAT);
    }

    /**
     * 获取延迟小时的日期
     * @param delayHour
     * @return
     */
    public static Date getDelayDateHour(int delayHour) {
        if(delayHour <= 0){
            return null;
        }
        Date day = DateUtil.offsetHour(new Date(), delayHour);
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
        String format = sf.format(day) + " 23:59:59";
        return new DateTime(format, DatePattern.NORM_DATETIME_FORMAT);
    }


    /**
     * 间隔多少秒
     * @param startDate
     * @param endDate
     * @return
     */
    public static String getMillisecond(Date startDate,Date endDate){
        long minute = DateUtil.between(startDate, endDate, DateUnit.MINUTE);
        return String.valueOf(minute*60*1000);
    }


    public static String checkDate(String dateStr) throws ParseException {
        if(StringUtils.isEmpty(dateStr)){
            return "";
        }
        if(!dateStr.contains("CST")){
            return "";
        }
        SimpleDateFormat sf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        return simpleDateFormat.format(sf.parse(dateStr));
    }

    public static int getMonthDiff(Date d1, Date d2) {
        Calendar c1 = Calendar.getInstance();
        Calendar c2 = Calendar.getInstance();
        c1.setTime(d1);
        c2.setTime(d2);
        if(c1.getTimeInMillis() < c2.getTimeInMillis()) return 0;
        int year1 = c1.get(Calendar.YEAR);
        int year2 = c2.get(Calendar.YEAR);
        int month1 = c1.get(Calendar.MONTH);
        int month2 = c2.get(Calendar.MONTH);
        int day1 = c1.get(Calendar.DAY_OF_MONTH);
        int day2 = c2.get(Calendar.DAY_OF_MONTH);
        // 获取年的差值 假设 d1 = 2015-8-16 d2 = 2011-9-30
        int yearInterval = year1 - year2;
        // 如果 d1的 月-日 小于 d2的 月-日 那么 yearInterval-- 这样就得到了相差的年数
        if(month1 < month2 || month1 == month2 && day1 < day2) yearInterval --;
        // 获取月数差值
        int monthInterval = (month1 + 12) - month2 ;
        if(day1 < day2) monthInterval --;
        monthInterval %= 12;
        return yearInterval * 12 + monthInterval;
    }


    /**
     * 给日期加上指定的分钟
     * @param date
     * @param deltaMinute 加上的分钟数
     * @return
     */
    public static Date addMinuteDate(Date date,int deltaMinute){

        Calendar newTime = Calendar.getInstance();
        newTime.setTime(date);
        newTime.add(Calendar.MINUTE,deltaMinute);//日期加n分
        return newTime.getTime();
    }

    /**
     * 相差天数
     * @param startDate
     * @param endDate
     * @return
     */
    public static int betweenDays(Date startDate,Date endDate){
        String startTime = DateUtil.formatDate(startDate);
        String endTime = DateUtil.formatDate(endDate);
        long between = DateUtil.between(DateUtil.parseDate(startTime), DateUtil.parseDate(endTime), DateUnit.DAY);
        return (int)between;
    }

    /**
     * 下载网络资源
     * @param fileUrl
     * @param diskPath
     * @param fileName
     * @return
     */
    public static String downLoadFromUrlBack(String fileUrl, String diskPath,String fileName) {
        String path = "";
        if (fileUrl != null) {
            //文件后缀
            String fileSuffix = fileUrl.substring(fileUrl.lastIndexOf("."));
            try {
                File file = new File(diskPath);
                if (!file.exists()) {
                    //创建文件夹
                    boolean mkdir = file.mkdir();
                    if (!mkdir) {
                        log.info("文件路径创建失败");
                    }
                }
                path = diskPath + fileName + fileSuffix;
                //文件下载
                HttpUtil.downloadFile(fileUrl, FileUtil.file(path));
            } catch (Exception e) {
                log.info("下载异常，异常信息为：" + e.getMessage());
            }
        }
        return path;
    }

    /**
     * 下载网络资源
     * @param urlStr
     * @param fileName
     * @param savePath
     * @throws IOException
     */
    public static void downLoadFromUrl(String urlStr,String savePath,String fileName) throws IOException {
        URL url = new URL(urlStr);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        //设置超时间
        conn.setConnectTimeout(10 * 1000);
        //设置一个请求头
        conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
        //获得输入流
        InputStream inputStream = conn.getInputStream();
        //获取数组
        byte[] getData = readInputStream(inputStream);
        //文件保存路径
        File saveDir = new File(savePath);
        if (!saveDir.exists()) {
            saveDir.mkdir();
        }
        File file = new File(saveDir + File.separator + fileName);
        FileOutputStream fos = new FileOutputStream(file);
        fos.write(getData);
        fos.close();
        inputStream.close();
    }

    public static  byte[] readInputStream(InputStream inputStream) throws IOException {
        byte[] buffer = new byte[1024];
        int len = 0;
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        while((len = inputStream.read(buffer)) != -1) {
            bos.write(buffer, 0, len);
        }
        bos.close();
        return bos.toByteArray();
    }

    /**
     * 获取自定义开始时间结束时间
     * @param type 0 本年 1 本季 2 本月 3 本周 4 当天
     * @return
     */
    public static Map<String,String> getStartDateAmdEndDate(Integer type){
        HashMap<String, String> map = new HashMap<>();
        LocalDateTime now = LocalDateTime.now();
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM");
        if(type == 0){
            LocalDateTime yearStart = now.with(TemporalAdjusters.firstDayOfYear()).with(LocalTime.MIN);
            LocalDateTime yearEnd = now.with(TemporalAdjusters.lastDayOfYear()).with(LocalTime.MAX);
            map.put("startDate",yearStart.format(fmt));
            map.put("endDate",yearEnd.format(fmt));
        }else if(type == 1){
            LocalDate currentDate = LocalDate.now();
            Month currentMonth = currentDate.getMonth();
            int currentYear = currentDate.getYear();

            Month startMonth;
            if (currentMonth == Month.JANUARY || currentMonth == Month.FEBRUARY || currentMonth == Month.MARCH) {
                startMonth = Month.JANUARY;
            } else if (currentMonth == Month.APRIL || currentMonth == Month.MAY || currentMonth == Month.JUNE) {
                startMonth = Month.APRIL;
            } else if (currentMonth == Month.JULY || currentMonth == Month.AUGUST || currentMonth == Month.SEPTEMBER) {
                startMonth = Month.JULY;
            } else {
                startMonth = Month.OCTOBER;
            }
            LocalDate startDate = LocalDate.of(currentYear, startMonth, 1);
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); // 定义日期格式
            String startDateString = startDate.format(formatter);

            LocalDate currentDate1 = LocalDate.now();
            Month currentMonth1 = currentDate1.getMonth();
            int currentYear1 = currentDate1.getYear();
            Month endMonth;
            if (currentMonth1 == Month.JANUARY || currentMonth1 == Month.FEBRUARY || currentMonth1 == Month.MARCH) {
                endMonth = Month.MARCH;
            } else if (currentMonth1 == Month.APRIL || currentMonth1 == Month.MAY || currentMonth1 == Month.JUNE) {
                endMonth = Month.JUNE;
            } else if (currentMonth1 == Month.JULY || currentMonth1 == Month.AUGUST || currentMonth1 == Month.SEPTEMBER) {
                endMonth = Month.SEPTEMBER;
            } else {
                endMonth = Month.DECEMBER;
            }

            int endDay = endMonth.length(false);
            LocalDate endDate = LocalDate.of(currentYear1, endMonth, endDay);
            String endDateString = endDate.format(formatter);
            map.put("startDate",startDateString);
            map.put("endDate",endDateString);
//            DateTime startTime = DateUtil.beginOfQuarter(new Date());
//            DateTime endTime = DateUtil.endOfQuarter(new Date());
//            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM");
//            map.put("startDate",sf.format(startTime));
//            map.put("endDate",sf.format(endTime));
        }else if(type == 2){
            LocalDateTime monthStart = now.with(TemporalAdjusters.firstDayOfMonth()).with(LocalTime.MIN);
            LocalDateTime monthEnd = now.with(TemporalAdjusters.lastDayOfMonth()).with(LocalTime.MAX);
            map.put("startDate",monthStart.format(fmt));
            map.put("endDate",monthEnd.format(fmt));
        }else if(type == 3){
            int dayOfWeek = now.getDayOfWeek().getValue();
            LocalDateTime weekStart = now.minusDays(dayOfWeek - 1).with(LocalTime.MIN);
            LocalDateTime weekEnd = now.plusDays(7 - dayOfWeek).with(LocalTime.MAX);
            map.put("startDate",weekStart.format(fmt));
            map.put("endDate",weekEnd.format(fmt));
        }else if(type == 4){
            LocalDateTime dayStart = now.with(LocalTime.MIN);
            LocalDateTime dayEnd = now.with(LocalTime.MAX);
            map.put("startDate",dayStart.format(fmt));
            map.put("endDate",dayEnd.format(fmt));
        }
        return map;
    }

    public static LocalDateTime getDateByYear(String yearStr){
        String today = DateUtil.today();
        String replace = today.replace(today.substring(0, 4), yearStr);
        DateTime parse = DateUtil.parse(replace);
       Instant instant = parse.toInstant();
        ZoneId zoneId = ZoneId.systemDefault();
        return instant.atZone(zoneId).toLocalDateTime();
    }

    /**
     * 数字加逗号
     * @param price
     * @return
     */
    public static String numberFormatData(BigDecimal price){
        NumberFormat numberformat = NumberFormat.getNumberInstance();
        return numberformat.format(price);
    }



    /**
     * 保留2位小数，直接截断
     * @param decimal
     * @return
     */
    public static BigDecimal setScaleBigDecimal(BigDecimal decimal){
        return decimal.setScale(2, RoundingMode.DOWN);
    }

    /**
     * 是否在指定的时间之内
     * @param date
     * @param begin
     * @param end
     * @return
     */
    public static boolean isEffectiveDate(Date date,Date begin,Date end){
        if(date.getTime()==begin.getTime() || date.getTime()==end.getTime()){
            return true;
        }
        Calendar dateCalendar = Calendar.getInstance();
        dateCalendar.setTime(date);

        Calendar beginCalendar = Calendar.getInstance();
        beginCalendar.setTime(begin);

        Calendar endCalendar = Calendar.getInstance();
        endCalendar.setTime(end);

        if(date.after(begin) && date.before(end)){
            return true;
        }else{
            return false;
        }

    }

    /**
     * 计算两个时间相差多少分钟
     * @param date1
     * @param date2
     * @return
     */
    public static long minuteDiff(Date date1, Date date2) {
        return (date1.getTime() - date2.getTime()) / (60 * 1000);
    }

    /**
     * 计算两个时间相差多少小时
     * @param date1
     * @param date2
     * @return
     */
    public static long hourDiff(Date date1, Date date2) {
        return (date1.getTime() - date2.getTime()) / (60 * 60 * 1000);
    }

    /**
     * 导入时值转金额
     * @param value
     * @return
     */
    public static BigDecimal getImportAmount(String value){
        BigDecimal cost = BigDecimal.ZERO;
        if(StringUtils.isEmpty(value)){
            return cost;
        }
        try {
            cost = new BigDecimal(value);
        } catch (Exception e) {
            //e.printStackTrace();
        }
        return cost;
    }

    /**
     * 获取折扣价
     * @param discount
     * @return
     */
    public static BigDecimal getDiscount(BigDecimal discount){
        BigDecimal subtract = new BigDecimal(10).subtract(discount);
        return subtract.multiply(new BigDecimal("0.1"));
    }

    /**
     * 时间是否过期
     * @param targetDate
     * @return
     */
    public static boolean timeIsExpired(Date targetDate) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String nowDate = simpleDateFormat.format(new Date());
        String targetDateStr = simpleDateFormat.format(targetDate);
        return targetDateStr.compareTo(nowDate) <= 0;
    }

    /**
     * 获取今日剩余秒数
     * @return
     */
    public static Long leftSecond(){
        Date nowDate = new Date();
        DateTime endTime = DateUtil.endOfDay(nowDate);
        return DateUtil.between(nowDate, endTime,DateUnit.SECOND);
    }

    public static void main(String[] args) throws Exception {

        System.out.println(getUUID());
        System.out.println(getUUID());
        System.out.println(getUUID());
        System.out.println(getUUID());
        System.out.println(getUUID());

    }
}
